//
//  OPEatListHeadView.m
//  OnePiece
//
//  Created by wsy on 15/10/29.
//  Copyright © 2015年 wsy. All rights reserved.
//

#import "OPEatListHeadView.h"

@implementation OPEatListHeadView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _picture = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH*318/550-40)];
        _picture.image = [UIImage imageNamed:@"meishihead1.jpg"];
        [self addSubview:_picture];
        _pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-80, SCREEN_WIDTH*318/550-55, 60, 15)];
        _pageControl.numberOfPages = 3;
        _pageControl.userInteractionEnabled = NO;
        [self addSubview:_pageControl];
        _mguide = [[UILabel alloc]initWithFrame:CGRectMake(45, SCREEN_WIDTH*318/550-30, 80, 15)];
        _mguide.text = @"米其林指南";
        _mguide.textColor = [UIColor colorWithWhite:0.173 alpha:1.000];
        _mguide.font = [UIFont systemFontOfSize:12];
        _mguide.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_mguide];
        UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(40, SCREEN_WIDTH*318/550-28, 5, 10)];
        view1.layer.cornerRadius = 2;
        view1.layer.masksToBounds = YES;
        view1.backgroundColor = [UIColor colorWithRed:0.890 green:0.424 blue:0.063 alpha:1.000];
        [self addSubview:view1];
        _rittips = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2+45, SCREEN_WIDTH*318/550-30, 80, 15)];
        _rittips.text = @"就餐小贴士";
        _rittips.textColor = [UIColor colorWithWhite:0.173 alpha:1.000];
        _rittips.font = [UIFont systemFontOfSize:12];
        _rittips.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_rittips];
        UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2+40, SCREEN_WIDTH*318/550-28, 5, 10)];
        view2.layer.cornerRadius = 2;
        view2.layer.masksToBounds = YES;
        view2.backgroundColor = [UIColor colorWithRed:0.890 green:0.424 blue:0.063 alpha:1.000];
        [self addSubview:view2];
        _mpicture = [[UIImageView alloc]initWithFrame:CGRectMake(30, SCREEN_WIDTH*318/550-10, SCREEN_WIDTH/2-60, (SCREEN_WIDTH/2-60)*0.6)];
        _mpicture.layer.cornerRadius = 5;
        _mpicture.layer.masksToBounds = YES;
        _mpicture.userInteractionEnabled = YES;
        _mpicture.image = [UIImage imageNamed:@"MGuide.jpg"];
        [self addSubview:_mpicture];
        _ritpicture = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2+30, SCREEN_WIDTH*318/550-10, SCREEN_WIDTH/2-60, (SCREEN_WIDTH/2-60)*0.6)];
        _ritpicture.layer.cornerRadius = 5;
        _ritpicture.layer.masksToBounds = YES;
        _ritpicture.userInteractionEnabled = YES;
        _ritpicture.image = [UIImage imageNamed:@"jiucanliyi.jpg"];
        [self addSubview:_ritpicture];
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(17, SCREEN_WIDTH*318/550+22+(SCREEN_WIDTH/2-60)*0.6, 5, 15)];
        view.layer.cornerRadius = 2;
        view.layer.masksToBounds = YES;
        view.backgroundColor = [UIColor colorWithRed:0.890 green:0.424 blue:0.063 alpha:1.000];
        [self addSubview:view];
        _maintitle = [[UILabel alloc]initWithFrame:CGRectMake(30, SCREEN_WIDTH*318/550+20+(SCREEN_WIDTH/2-60)*0.6, 100, 20)];
        _maintitle.text = @"精彩食记";
        _maintitle.textColor = [UIColor colorWithWhite:0.176 alpha:1.000];
        _maintitle.font = [UIFont systemFontOfSize:18];
        [self addSubview:_maintitle];
        
        [NSTimer scheduledTimerWithTimeInterval:4 target:self selector:@selector(changeHeadImg) userInfo:nil repeats:YES];
    }
    return self;
}

- (void)changeHeadImg
{
    [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        if (_pageControl.currentPage == 2) {
            _pageControl.currentPage = 0;
            _picture.image = [UIImage imageNamed:@"meishihead1.jpg"];
        }else if (_pageControl.currentPage == 1){
            _pageControl.currentPage = 2;
            _picture.image = [UIImage imageNamed:@"meishihead2.jpg"];
        }else{
            _pageControl.currentPage = 1;
            _picture.image = [UIImage imageNamed:@"meishihead3.jpg"];
        }
        
    } completion:nil];
}

@end
